package org.mj.im.server.netty.processor.factory;

import org.mj.im.common.enums.IMCmdType;
import org.mj.im.server.holder.SpringContextHolder;
import org.mj.im.server.netty.processor.MessageProcessor;
import org.mj.im.server.netty.processor.impl.GroupMessageProcessor;
import org.mj.im.server.netty.processor.impl.HeartbeatProcessor;
import org.mj.im.server.netty.processor.impl.LoginProcessor;
import org.mj.im.server.netty.processor.impl.PrivateMessageProcessor;

public class MessageProcessorFactory {
    public static MessageProcessor<?> getProcessor(IMCmdType cmd){
        return switch (cmd) {
            //登录
            case LOGIN -> SpringContextHolder.getApplicationContext().getBean(LoginProcessor.class);
            //心跳
            case HEART_BEAT -> SpringContextHolder.getApplicationContext().getBean(HeartbeatProcessor.class);
            //单聊消息
            case PRIVATE_MESSAGE -> SpringContextHolder.getApplicationContext().getBean(PrivateMessageProcessor.class);
            //群聊消息
            case GROUP_MESSAGE -> SpringContextHolder.getApplicationContext().getBean(GroupMessageProcessor.class);
            default -> null;
        };
    }
}
